import { EventTouch } from 'cc';
import { ccclass, ccmodifier } from '../decorators';
import { BaseScreen } from './BaseScreen';
import { BaseStack } from './BaseStack';

/**
 * - 作者: DoooReyn
 * - 日期: 2023.10.31
 * - 名称: Screen
 * - 描述: 视图-一级界面层
 */
@ccclass()
@ccmodifier('Screen')
export class Screen extends BaseStack {
    /** 一级界面同时只允许存在一个，因此添加时需要移除上一个 */
    public async add(path: string, bundle: string = 'resources', data?: any): Promise<void> {
        const children = this.node.children;
        const last = children[children.length - 1];
        await last?.getComponent(BaseScreen)?.close();
        await super.add(path, bundle, data);
    }

    protected onTouchScreen(e: EventTouch): void {
        e.preventSwallow = true;
        this.logger.debug('允许触摸继续传递');
    }
}
